/*
* 修改密码
* */
var user = {
    id:0,
    userName:'',
    userPassword:''
}
$("#re_btn").click(function () {
    let userName = $("#userName").html();
    let newPsw = $("#new-password").val();
    user.userName = userName;
    user.userPassword = newPsw;
    /*更新密码*/
    $.ajax({
        url:'/user/update',
        type:'get',
        data:user,
        success:function (obj) {
            lightyear.notify(obj, 'success', 2000, 'mdi mdi-close-circle-outline', 'top', 'center');
            setTimeout(function () {
                window.location.reload();
            },1000);
        }
    });
});
/*检查旧密码输入是否正确*/
function checkOldPsw() {
    let userName = $("#userName").html();
    let oldPsw = $("#old-password").val();
    $.ajax({
       url:"/user/check",
       type:'get',
       data:{
           'userName':userName,
           'oldPsw':oldPsw
       } ,
        success:function (obj) {
           console.log(obj);
            if("" === obj){
                lightyear.notify('旧密码错误!', 'danger', 2000, 'mdi mdi-close-circle-outline', 'top', 'center');
            }else{
               user.id = obj;
            }
        }
    });
}

/*新密码一些校验*/
function checkNewPsw() {
    let oldPsw = $("#old-password").val();
    let newPsw = $("#new-password").val();
    let confirmPsw = $("#confirm-password").val();
    if(oldPsw == newPsw){
        lightyear.notify('新密码不能与旧密码一致!', 'danger', 2000, 'mdi mdi-close-circle-outline', 'top', 'center');
    }else if(newPsw != confirmPsw){
        lightyear.notify('两次输入的密码不一致，请重新输入!', 'danger', 2000, 'mdi mdi-close-circle-outline', 'top', 'center');
    }else{
        $("#re_btn").removeAttr("disabled");
    }
}